﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Com.queryzer2.Domain;
using common;

using common.pages;
using Com.queryzer2.Domain.Entities;
using Com.AlbLab.CR.Stampe;

namespace Com.AlbLab.CR.Web.pages
{
    public partial class RicercaPratica : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ddlFornitore.DataSource = BasePage.Services.AnagraficheService.getListaVenditori().Values;
                ddlFornitore.DataValueField = "Id_ven_cod_contr_disp";
                ddlFornitore.DataTextField = "Ven_ragsoc";
                ddlFornitore.DataBind();
                ddlFornitore.SelectedValue = "NaN";
                ddlTipoPratica.DataSource = BasePage.Services.AnagraficheService.getListaServizi().Values;
                ddlTipoPratica.DataValueField = "Id_ser_cod_servizio";
                ddlTipoPratica.DataTextField = "Ser_des_servizio_ext";
                ddlTipoPratica.DataBind();
                ddlTipoPratica.SelectedValue = "NaN";
            }
        }

        protected void Page_DataBind(object sender, EventArgs e)
        {
          
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                //List<GEP_TESTATA> searchResult = Services.AnagraficheService.ricercaPratiche(ddlTipoPratica.SelectedValue, "DP1616" ddlFornitore.SelectedValue, txtPiva.Text, txtRagsoc.Text, txtDa.Text, txtA.Text);
                List<GEP_TESTATA> searchResult = Services.AnagraficheService.ricercaPratiche(ddlTipoPratica.SelectedValue, ddlFornitore.SelectedValue, txtPiva.Text, txtPod.Text,txtPrt.Text, txtDa.Text, txtA.Text);
              
                    GrigliaGenerica1.NumColonne = 5;
                    GrigliaGenerica1.H0 = "Data Arrivo";
                    GrigliaGenerica1.H1 = "Cliente";
                    GrigliaGenerica1.H2 = "Ente Fornitore";
                    GrigliaGenerica1.H3 = "Tipo Pratica";
                    //IList<ConfAziendaEntity> searchResult = null;
                    //searchResult = null;// base.ServiceConfAzienda().LoadConferimentoByPartialRagSoc(textFilter.Text.Trim(), false);
                    GrigliaGenerica1.DataSource = common.ToGenericListTransformers.transform(searchResult);
                    GrigliaGenerica1.Visible = true;
                    C1.Visible = true;
                    
            }
            catch (ManagedException e0x)
            {
                ((BasePage)this.Page).info.AddMessage(e0x);
            }
        }

        protected void GrigliaGenerica1_OnSelect(string commandName, GenericListDTO row)
        {
            GrigliaGenerica1.Clear();
            common.TempSession.setBag("CODICE_PRATICA", row.Id.Split('/')[0]);
            Response.Redirect("Pratica.aspx");
        }

        protected void test_Click(object sender, EventArgs e)
        {
            PdfBuilder b0 = new PdfBuilder();
            byte[] buff=b0.getPdf(PdfSelector.ORDINE_LAV_1, new ORDINE_LAV_1EventArgs());
            this.Response.Clear();
            this.Response.ContentType = "file/pdf";
            this.Response.AppendHeader("Content-Disposition", "attachment; filename=" + "Ordine_di_Lavoro.pdf");
            this.Response.BinaryWrite(buff);
            buff = null;
            this.Response.End();
        }
    }
}